import requests
import time
import bs4

url = "http://m.bizhi360.com/weimei/list_18.html"

resp = requests.get(url)
resp.close()

resp.encoding = "utf-8"

# print(resp.text)

page = bs4.BeautifulSoup(resp.text,"html.parser")

imglist = page.find('div',attrs = {"class":"imglist"})
src_list = imglist.find_all('a')

pre_url = "http://m.bizhi360.com"

for src in src_list:
    # print(src.attrs['src'])
    # print(src.get('href'))
    href = pre_url + src.get("href")

    resp_href = requests.get(href)
    resp_href.close()
    href_page = bs4.BeautifulSoup(resp_href.text,"html.parser")

    div = href_page.find('div',attrs={"class":"article"})
    img = div.find('img')

    img_src = img.get('src')
    img_resp = requests.get(img_src)
    img_resp.close()

    image_name = './img/' + img_src.split("/")[-1]

    with open(image_name,mode = 'wb') as f:
        f.write(img_resp.content)
        print(image_name)

    time.sleep(1)

    # break

resp.close()
pass
# print(imglist.text)

